<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成器函数</title>
</head>

<body>
    <script>
        //生成器是一个特殊函数
        //异步编程 纯回调函数 node fs ajax mongodb
        //函数代码的分隔符
        function* gen() {
            // console.log("hello generator")
            console.log(111)
            yield '一只没有耳朵';
            console.log(222)
            yield '一只没有尾部';
            console.log(333);
            yield '真奇怪';
            console.log(444);
        }

        let iterator = gen();
        // console.log(iterator)
        iterator.next();
        iterator.next();
        iterator.next();
        iterator.next();

        //遍历
        for(let v of gen()){
            console.log(v)
        }

        

    </script>
</body>

</html>